<?php
require_once "filter.php";
require_once "Connection.php";
session_start();

$conn = new Connection();
$categories = $conn->fetchCategory($_SESSION['LOGIN_INFO']['id']);
$categories = urldecode($categories);
$categories = json_decode($categories, true);

if(empty($categories)){
	echo json_encode(array('status'=>false,'msg'=>'發生錯誤'));
	exit;
}


$msg = '';

$msg .= '<tbody>';

if (! empty($categories[0])) {
    $the_uncategory_index = count($categories) - 1;
    foreach ($categories as $category_key=>$categories_val) {
        if ($category_key != $the_uncategory_index) {
            $msg .= '<tr>';
            $msg .= '<td class="title" id="category_title_'.$category_key.'">'.$categories_val.'</td>';
            $msg .= '<td class="rename" id="rename_button_'.$category_key.'"><input type="button" value="重新命名" onclick="showCategoryRenameTitle(\''.$category_key.'\')"/></td>';
            $msg .= '<td id="deleteCategory_'.$category_key.'"><img src="styles/images/icons/unsubscribe.png" style="cursor:pointer;" onclick="deleteCategory(\''.$category_key.'\')"/></td>';
            $msg .= '</tr>';
            $msg .= '<tr class="feed-row"><td colspan="3">&nbsp;</td></tr>';
        }
    }
}



$msg .= '</tbody>';

echo json_encode(array('status'=>true,'msg'=>$msg));

?>